from django.shortcuts import render
from talk.models import talksInfo
from rest_framework.views import APIView
from rest_framework.response import Response
from talk.serializer import TalkSerializer
# Create your views here.

# def talkView(request):
#     title = '讨论'
#     talkslist = talksInfo.objects.all()
#     t = request.GET.get('t', '')
#     if t:
#         talkslist = talkslist.filter(types=t)
#
#     return render(request, 'talk.html', locals())

class talkView(APIView):
    def get(self, request):
        context = {'state': 'success', 'msg': "获取成功", 'data': {}}
        context['data']['TalksInfo'] = []
        sort = request.GET.get('sort', '')
        c = talksInfo.objects.all()
        if sort:
            c = c.filter(types=sort)
        context['data']['TalksInfo'].append(TalkSerializer(instance=c[::], many=True).data)

        return Response(context)
